import numpy as np
# 传入形状 5 或者 (5)构造的是一维数组 元素个数5
arr1 = np.ones((5));
print(f"数组内容:{arr1},数组长度{len(arr1)}")

# 传入形状(2,3)
arr2 = np.ones((2,3));
arr2[0][0] = 2
arr2[0][1] = 3
print(f"数组内容:\n{arr2}")
"""
[[2. 3. 1.]
 [1. 1. 1.]]
"""
# 传入形状(2,3,6)
arr3 = np.ones((2,3,6))
print(f"数组内容:\n{arr3}")
"""
[[[1. 1. 1. 1. 1. 1.]
  [1. 1. 1. 1. 1. 1.]
  [1. 1. 1. 1. 1. 1.]]
  
 [[1. 1. 1. 1. 1. 1.]
  [1. 1. 1. 1. 1. 1.]
  [1. 1. 1. 1. 1. 1.]]]
"""
# 同时，我们还可以使用数组的 .shape 属性查看 arr1 和 arr2 的形状。
print( arr1.shape ) # (5,)
print( arr2.shape ) # (2, 3)
print( arr3.shape ) # (2, 3, 6)

# ================================
# 创建一维数组
arr1 = np.arange(10)
print(arr1) # [0 1 2 3 4 5 6 7 8 9]
# 升级为二维数组
arr2 = arr1.reshape( (1,-1) )
print(arr2) # [[0 1 2 3 4 5 6 7 8 9]]
arr3 = arr1.reshape( (2,-1) )
print(arr3)
"""
[[0 1 2 3 4]
 [5 6 7 8 9]]
"""

# 创建二维数组
arr2 = np.arange(10).reshape(2,5)
print(arr2)
"""
[[0 1 2 3 4]
 [5 6 7 8 9]]
"""
# 降级为一维数组
arr2 = np.arange(10).reshape(2,5)
arr1 = arr2.reshape( -1 )
print(arr1) # [0 1 2 3 4 5 6 7 8 9]
arr1 = arr2.reshape( 10 )
print(arr1) # [0 1 2 3 4 5 6 7 8 9]